//
//  SQWorkDetailsViewController.m
//  energy
//
//  Created by 周曼迪 on 2021/7/15.
//

#import "SQWorkDetailsViewController.h"

#import "SQWorkDetailsModel.h"
#import "SQSpecialRegionModel.h"

#import "SQCodeViewController.h"
#import "SQSpecialDetailsViewController.h"

@interface SQWorkDetailsViewController ()<BaseTableVCInterface>

@end

@implementation SQWorkDetailsViewController

- (void)viewDidLoad {
    self.tableViewInterface = self;
    [super viewDidLoad];
    
    if ([self.type isEqualToString:@"1"]) {
        self.navigationItem.title = @"作业详细";
    }else if ([self.type isEqualToString:@"2"]){
        self.navigationItem.title = @"专项检查";

    }
  
    
    [self getWorkDetailsData];
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self getWorkDetailsData];
    }];
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getWorkDetailsData) name:@"codeView" object:nil];
    
    LC_WEAK_SELF
    self.cellEvent = ^(int key) {
        if ([weakSelf.type isEqualToString:@"1"]) {
            SQWorkDetailsModelData * dataModel = weakSelf.dataSouece[key];
            SQCodeViewController * codeVC = SQCodeViewController.new;
            codeVC.ipm_id = dataModel.sal_operation_link_id;
            codeVC.ipm_id_text = dataModel.sal_operation_link_text;
            codeVC.type = @"2";
            codeVC.sal_sa = dataModel.sal_sa;
            [weakSelf pushVC:codeVC];
        }else if ([weakSelf.type isEqualToString:@"2"]){
            SQSpecialRegionModelData * dataModel = weakSelf.dataSouece[key];
            SQSpecialDetailsViewController * specialDetailsVC = SQSpecialDetailsViewController.new;
            specialDetailsVC.sa_sc = weakSelf.sa_sc;
            specialDetailsVC.sa_scText = dataModel.sr_name;
            specialDetailsVC.sr_id = dataModel.sr_id;
            specialDetailsVC.detailsID = weakSelf.detailsID;
            [weakSelf pushVC:specialDetailsVC];

        }
        
        
        
        
       
    };
    
}

-(void)getWorkDetailsData{
    if ([self.type isEqualToString:@"1"]) {
        
        [SQWorkDetailsModel getDataWithParams:@{@"sa_id":self.detailsID} WithCallBack:^(SQWorkDetailsModel * data) {
            [self detailModelwithArr:data.data withCallBack:nil];
            [self reloadTableView];
        }];
        
    }else if ([self.type isEqualToString:@"2"]){
        [SQSpecialRegionModel getDataWithParams:@{@"srp_person_id":UID,@"sa_id":self.detailsID} WithCallBack:^(SQSpecialRegionModel * data) {
            [self detailModelwithArr:data.data withCallBack:nil];
            [self reloadTableView];
        }];
    }
    
   
    
}


-(NSInteger)rowsCount:(NSInteger)section{
    return self.dataSouece.count;
}

-(BaseModel *)modelForCell:(NSIndexPath *)indexPath{
    return self.dataSouece[indexPath.row];
}


- (NSArray<NSArray<NSString *> *> *)classArr{
    return @[@[@"SQWorkDetailsTableViewCell"]];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
